﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JTicket.Common
{
    public class StringHelp
    {
        /// <summary>
        /// 截取指定长度的字符串
        /// </summary>
        /// <param name="Value">字符串</param>
        /// <param name="Length">截取长度</param>
        /// <returns></returns>
        public static string CutString(string Value, int Length)
        {
            ASCIIEncoding encoding = new ASCIIEncoding();
            int num = 0;
            string str = "";
            byte[] bytes = encoding.GetBytes(Value);
            for (int i = 0; i < bytes.Length; i++)
            {
                if (bytes[i] == 0x3f)
                {
                    num += 2;
                }
                else
                {
                    num++;
                }
                try
                {
                    str += Value.Substring(i, 1);
                }
                catch
                {
                    return str;
                }
                if (num > Length)
                {
                    return str;
                }
            }
            return str;
        }
        /// <summary>
        /// 以时间为种子生成文件名称
        /// </summary>
        /// <returns></returns>
        public static string GenerateFileName()
        {
            return DateTime.Now.ToString("yyyyMMddhhmmss") + DateTime.Now.Millisecond.ToString();

        }
        public bool GetChar(string str, string kstr)
        {
            int i = str.IndexOf(kstr);
            if (i != -1)
                return true;
            else
                return false;
        } 
    }
}